package com.spring.soundsystem;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import java.util.HashMap;
import java.util.Map;

@Aspect
public class TrackCounter {

    private Map<Integer, Integer> trackCounter = new HashMap<Integer, Integer>();

    @Pointcut("execution(public * com.spring.soundsystem.CompactDisc.playTrack(int)) && args(trackNumber)")
    public void trackPlayed(int trackNumber){}

    @Before("trackPlayed(trackNumber)")
    public void countTrack(int trackNumber){
        int currentCount = getPlayCount(trackNumber);
        trackCounter.put(trackNumber,currentCount+1);
    }

    public  int getPlayCount(int trackNumber){
        return trackCounter.containsKey(trackNumber)?trackCounter.get(trackNumber):0;
    }



}
